﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace ValidationUnity
{
    public class RecordLoginId
    {
        public static string GetSettingString(string settingName)
         {
            try
             {
                 string settingString = ConfigurationManager.AppSettings[settingName].ToString();
                 return settingString;
             }
             catch (Exception)
             {
                 return null;
            }
         }

        /// <summary>
        /// 更新设置
        /// </summary>
        /// <param name="settingName"></param>
        /// <param name="valueName"></param>
         public static void UpdateSettingString(string settingName, string valueName)
         {
             Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

             if (ConfigurationManager.AppSettings[settingName] != null)
             {
                 config.AppSettings.Settings.Remove(settingName);
             }
             config.AppSettings.Settings.Add(settingName, valueName);
             config.Save(ConfigurationSaveMode.Modified);
             ConfigurationManager.RefreshSection("appSettings");
         }
    }
}
